(function() {
    angular.module('app').component('productSourceComponent', {
        templateUrl: 'app/components/product.source.component/product.source.component.html',
        controller: productSourceComponent,
        controllerAs: 'vm'
    });

    productSourceComponent.$inject = ['$rootScope','$scope','$http','$loading'];

    function productSourceComponent($rootScope,$scope,$http,$loading) {
    	var vm = this;

    	vm.productSource = [];
    	vm.product = {};
        vm.getHttp = getHttp;
    	$('.modal').modal();

    	var clearFun = $rootScope.$on('product_source_component_modal_EV',function(e,prod){
    		vm.product = prod;
    		vm.productSource.length = 0;

            $loading.start('prodsource');
    		vm.getHttp(prod.numberId);
            
            // console.log('product_source_component_modal_EV');
    		$('#modal-product-source').modal('open');
    	});

    	$scope.$on('$destroy',function(){
    		clearFun();
    	});

    	function getHttp(numberId){
    		
            vm.productSource.length = 0;
            $http({
                method: 'GET',
                params: {
                    numberId: numberId
                },
                url: "/marketconditions/product/getSameProduct.htm",
                headers: {
                    'Accept': 'application/json, text/javascript, */*'
                }
            }).success(function(resp) {
                vm.productSource = resp.data.offerList;

                // console.log(vm.productSource);

                $loading.finish('prodsource');
                
            }).error(function(resp) {
                $loading.finish('prodsource');
            });

    		
    	}


              
    }
})();
